package com.plan.service.card.impl;

import com.plan.base.util.DateUtil;
import com.plan.controller.card.request.DayPlanStatPageListReq;
import com.plan.controller.card.response.DayPlanStatPageListRes;
import com.plan.dao.mapper.card.DayPlanStatMapper;
import com.plan.entity.card.DayPlanStat;
import com.plan.service.card.DayPlanStatService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 每日计划统计
 *
 * @author zcl
 */
@Service
public class DayPlanStatServiceImpl implements DayPlanStatService {
    @Resource
    private DayPlanStatMapper statMapper;

    @Override
    public List<DayPlanStatPageListRes> pageList(DayPlanStatPageListReq req) {
        List<DayPlanStat> list = statMapper.getPageList(req);
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyList();
        }
        return list.stream().map(x -> {
            DayPlanStatPageListRes p = new DayPlanStatPageListRes();
            p.setId(x.getId());
            p.setTaskNum(x.getTaskNum());
            p.setDate(DateUtil.yearMonthDayToDateString(x.getYearMontDay()));
            p.setYearMonthDay(x.getYearMontDay());
            p.setWeek(DateUtil.getChineseWeekday(x.getYearMontDay()));
            return p;
        }).collect(Collectors.toList());
    }
}
